import dayjs from "dayjs";
import { message } from "@/utils/message";
import { handleTree } from "@/utils/tree";
// import { getUserList } from "@/api/system";
import { ElMessageBox } from "element-plus";
import { type PaginationProps } from "@pureadmin/table";
import { reactive, ref, computed, onMounted } from "vue";

export function applydocumentHook() {
  const treeData = ref([]);
  const searchfrom = ref("");
  const switchLoadMap = ref({});
  const selectionarr = ref([]);
  const dialogFlowVisible = ref(false);
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 10,
    currentPage: 1,
    background: true
  });
  //详情列表
  const detailform = ref({
    flowname: "",
    tablename: "",
    flowevent: [
      { eventname: "请假是申请单-审批完成事件" },
      { eventname: "请假是申请单-审批终止事件" }
    ],
    flowrange: true,
    bumen: ["技术中心"]
  });

  function queryTreeData() {
    const data: any[] = [
      {
        name: "常用表单",
        type: 1,
        parentId: 0,
        sort: 0,
        leaderUserId: 1,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 100,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "工会",
        type: 2,
        parentId: 100,
        sort: 1,
        leaderUserId: 104,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 101,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "研发部门",
        type: 3,
        parentId: 101,
        sort: 1,
        leaderUserId: 104,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 103,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "市场部门",
        type: 3,
        parentId: 102,
        sort: 1,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 108,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "财务中心",
        type: 2,
        parentId: 100,
        sort: 2,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 102,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "市场部门",
        type: 3,
        parentId: 101,
        sort: 2,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 1,
        id: 104,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "财务部门",
        type: 3,
        parentId: 102,
        sort: 2,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 109,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "测试部门",
        type: 3,
        parentId: 101,
        sort: 3,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 105,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "财务部门",
        type: 3,
        parentId: 101,
        sort: 4,
        leaderUserId: 103,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 1,
        id: 106,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "运维部门",
        type: 3,
        parentId: 101,
        sort: 5,
        leaderUserId: null,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 107,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "金湖分公司",
        type: 1,
        parentId: 1,
        sort: 0,
        leaderUserId: 1,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 200,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      },
      {
        name: "徐州分公司",
        type: 1,
        parentId: 2,
        sort: 0,
        leaderUserId: 1,
        phone: "15888888888",
        email: "ry@qq.com",
        status: 0,
        id: 300,
        createTime: 1609837427000,
        remark: "备注、备注、备注、备注、备注、备注、备注"
      }
    ];
    treeData.value = handleTree(data);
    console.log(treeData.value);
  }

  async function onSearch() {
    loading.value = true;
    queryTreeData();
    setTimeout(() => {
      loading.value = false;
    }, 500);
  }

  onMounted(() => {
    onSearch();
  });

  return {
    treeData,
    searchfrom,
    dialogFlowVisible
  };
}
